var option=null
var path='${pageContext.request.contextPath}';
$("#APKName").blur(function (){
    $.getJSON(path+"/appInfo/APKNameExist","APKName="+$("#APKName").val(),function (data){
        if (data.APKName=="true"){
            $(".apknameExist").html("该APK名称可以使用");
        }else {
            $(".apknameExist").html("该APK名称已存在");
        }
    })
})
var backBtn=null;
$(function () {
    backBtn = $("#back");
    backBtn.on("click",function(){
        //alert("view : "+referer);
        if(referer != undefined
            && null != referer
            && "" != referer
            && "null" != referer
            && referer.length > 4){
            window.location.href = referer;
        }else{
            history.back(-1);
        }
    });
    $.getJSON(path+"/category/fenlei1",'',function (data){
        option="<option value='0'>请选择</option>";
        for (var i = 0; i < data.length; i++) {
            if($("#level1").val()==+data[i].id){
                option+="<option selected='selected' value='"+data[i].id+"'>"+data[i].categoryName+"</option>"
            }else {
                option+="<option value='"+data[i].id+"'>"+data[i].categoryName+"</option>"
            }
        }
        $("#categoryLevel1").html(option);
    })
    $.ajax({
        type: "GET",
        url:path+"/category/fenlei2",
        data:{parentId:$("#level1").val()},
        dataType:"json",
        success:function (data){
            option="<option value='0'>请选择</option>";
            for (var i = 0; i < data.length; i++) {
                if($("#level2").val()==data[i].id){
                    option+="<option selected='selected' value='"+data[i].id+"'>"+data[i].categoryName+"</option>"
                }else{
                    option+="<option value='"+data[i].id+"'>"+data[i].categoryName+"</option>"
                }
            }
            $("#categoryLevel2").html(option);
        }
    })
    $.getJSON(path+"/category/fenlei3",{parentId:$("#level2").val()},function (data){
        option="<option value='0'>请选择</option>";
        for (var i = 0; i < data.length; i++) {
            if($("#level3").val()==+data[i].id){
                option+="<option selected='selected' value='"+data[i].id+"'>"+data[i].categoryName+"</option>"
            }else {
                option+="<option value='"+data[i].id+"'>"+data[i].categoryName+"</option>"
            }
        }
        $("#categoryLevel3").html(option);
    })

    $.getJSON(path+"/category/fenlei1",'',function (data){
        option="<option value='0'>请选择</option>";
        for (var i = 0; i < data.length; i++) {
            option+="<option value='"+data[i].id+"'>"+data[i].categoryName+"</option>"
        }

        $("[name=categoryLevel1]").html(option);
    })

    $("#categoryLevel1").change(function (){
        var categoryLevel1=$("#categoryLevel1").val();
        if(categoryLevel1!="" && categoryLevel1!=null){
            $.ajax({
                type: "GET",
                url:path+"/category/fenlei2",
                data:{parentId:categoryLevel1},
                dataType:"json",
                success:function (data){
                    option="<option value='0'>请选择</option>";
                    for (var i = 0; i < data.length; i++) {
                        option+="<option value='"+data[i].id+"'>"+data[i].categoryName+"</option>"
                    }
                    $("#categoryLevel2").html(option);

                },
                error:function (data){
                    alert("加载二级菜单失败")
                }
            })
        }else{
            $("#categoryLevel2").html("");

            option="<option value='0'>请选择</option>";
            $("#categoryLevel2").html(option);

        }
        $("#categoryLevel3").html("");

        option="<option value='0'>请选择</option>";
        $("#categoryLevel3").html(option);

    })
    $("#categoryLevel2").change(function (){
        var categoryLevel2=$("#categoryLevel2").val();
        if(categoryLevel2!="" && categoryLevel2!=null) {
            $.ajax({
                type: "GET",
                url: path+"/category/fenlei3",
                data: {parentId: categoryLevel2},
                dataType: "json",
                success: function (data) {
                    option = "<option value='0'>请选择</option>";
                    for (var i = 0; i < data.length; i++) {
                        option += "<option value='" + data[i].id + "'>" + data[i].categoryName + "</option>"
                    }

                    $("#categoryLevel3").html(option);
                },
                error:function (data){
                    alert("加载三级菜单失败")
                }
            })
        }
    })
    $("#levell1").change(function (){
        var categoryLevel1=$("#levell1").val();
        if(categoryLevel1!="" && categoryLevel1!=null){
            $.ajax({
                type: "GET",
                url:path+"/category/fenlei2",
                data:{parentId:categoryLevel1},
                dataType:"json",
                success:function (data){
                    option="<option value='0'>请选择</option>";
                    for (var i = 0; i < data.length; i++) {
                        option+="<option value='"+data[i].id+"'>"+data[i].categoryName+"</option>"
                    }
                    $("#levell2").html(option);
                },
                error:function (data){
                    alert("加载二级菜单失败")
                }
            })
        }else{

            $("#levell2").html("");
            option="<option value='0'>请选择</option>";

            $("#levell2").html(option);
        }

        $("#levell3").html("");
        option="<option value='0'>请选择</option>";

        $("#levell3").html(option);
    })
    $("#levell2").change(function (){
        var categoryLevel2=$("#levell2").val();
        if(categoryLevel2!="" && categoryLevel2!=null) {
            $.ajax({
                type: "GET",
                url: path+"/category/fenlei3",
                data: {parentId: categoryLevel2},
                dataType: "json",
                success: function (data) {
                    option = "<option value='0'>请选择</option>";
                    for (var i = 0; i < data.length; i++) {
                        option += "<option value='" + data[i].id + "'>" + data[i].categoryName + "</option>"
                    }
                    $("#levell3").html(option);

                },
                error:function (data){
                    alert("加载三级菜单失败")
                }
            })
        }
    })
})